﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Web.Security;
using System.Data;

namespace HQWeb.Procurement
{
    public partial class Approve : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            VerdictIsLogin();
            if (!IsPostBack)
            {
                string PID = Request["ID"].ToString();
                Model.Procurement.T_PUB_PURCHASE purchase = new Model.Procurement.T_PUB_PURCHASE();
                BLL.Procurement.T_PUB_PURCHASE bll = new BLL.Procurement.T_PUB_PURCHASE();
                purchase = bll.GetModel(PID);
                BindBranch(PID);
                this.lbltitle.Text = purchase.TITLE;
                //this.lblnum.Text = purchase.NUM.ToString();
                this.lblremark.Text = purchase.REMARK;
                this.applytime.Text = Convert.ToDateTime(purchase.APPLICANT_TIME.ToString()).ToShortDateString();
                this.endtime.Text = Convert.ToDateTime(purchase.END_TIME.ToString()).ToShortDateString();

            }
        }
        #region 绑定材料
        private void BindMaterialName(int Matereial_id)
        {

            BLL.SysManage.T_PUB_MATERIAL bll = new BLL.SysManage.T_PUB_MATERIAL();
            Model.SysManage.T_PUB_MATERIAL material = bll.GetModel(Matereial_id);
            if (material != null)
            {
                this.lblmaterial.Text = material.MATERIAL_NAME;
            }
        }
        #endregion

        #region  绑定分店
        private void BindBranch(string id)
        {
            Model.Procurement.T_PUB_PURCHASE purchase = new Model.Procurement.T_PUB_PURCHASE();
            BLL.Procurement.T_PUB_PURCHASE bll = new BLL.Procurement.T_PUB_PURCHASE();
            purchase = bll.GetModel(id);
            int branchid = Convert.ToInt32(purchase.BRANCH_ID.ToString());
            Model.SysManage.T_PUB_BRANCH branch = new Model.SysManage.T_PUB_BRANCH();
            BLL.SysManage.T_PUB_BRANCH bllbranch = new BLL.SysManage.T_PUB_BRANCH();
            branch = bllbranch.GetModel(branchid);
            if (branch != null)
            {
                this.lblbranch.Text = branch.BRANCH_NAME;
            }
        }
        #endregion

        #region 审批通过
        protected void btnOK_Click(object sender, EventArgs e)
        {
            string PID = Request["ID"].ToString();
            Model.Procurement.T_PUB_PURCHASE purchase = new Model.Procurement.T_PUB_PURCHASE();
            BLL.Procurement.T_PUB_PURCHASE bll = new BLL.Procurement.T_PUB_PURCHASE();
            purchase = bll.GetModel(PID);
            purchase.APPROVER=Convert.ToInt32(Session["USER_ID"].ToString());
            purchase.NOTATION = this.txtnotes.Text;
            purchase.STATE = "3";
            bll.Update(purchase);
            Universal.CommonMethod.SaveOpreation(Convert.ToInt32(Session["USER_ID"]), "采购申请" + purchase.TITLE + " 状态为已审批", DateTime.Now);
        }
        #endregion

        #region 审批驳回
        protected void btnNOT_Click(object sender, EventArgs e)
        {
            string PID = Request["ID"].ToString();
            Model.Procurement.T_PUB_PURCHASE purchase = new Model.Procurement.T_PUB_PURCHASE();
            BLL.Procurement.T_PUB_PURCHASE bll = new BLL.Procurement.T_PUB_PURCHASE();
            purchase = bll.GetModel(PID);
            purchase.APPROVER = Convert.ToInt32(Session["USER_ID"].ToString());
            purchase.NOTATION = this.txtnotes.Text;
            purchase.STATE = "2";
            bll.Update(purchase);
            Universal.CommonMethod.SaveOpreation(Convert.ToInt32(Session["USER_ID"]), "采购申请" + purchase.TITLE + " 状态为审批不通过", DateTime.Now);
        }
        #endregion
    }
}